//https://leetcode.cn/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/submissions/544108702/

int* reverseBookList(struct ListNode* head, int* returnSize) {

    struct ListNode* cur = head;
    int count = 0;
    while (cur)
    {
        count++;
        cur = cur->next;

    }
    *returnSize = count;

    cur = head;
    int* ret = (int*)malloc(sizeof(int) * count);
    if (ret == NULL)
    {
        perror("malloc fail\n");
        return NULL;
    }

    while (count > 0)
    {
        ret[count - 1] = cur->val;
        count--;
        cur = cur->next;

    }

    return ret;



}